import { NestFactory } from '@nestjs/core';
import {
	FastifyAdapter,
	NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AllExceptionFilter } from './interceptors/exception';
import { RequestInterceptor } from './interceptors/request';
import { ResponseInterceptor } from './interceptors/response';
import { LoggingInterceptor } from './interceptors/logger';
import { RootModule } from './root.module';
import config from './config/config';

async function bootstrap() {
	//使用fastify适配器
	const app = await NestFactory.create<NestFastifyApplication>(
		RootModule,
		new FastifyAdapter({ logger: false }),
	);

	//全局异常过滤器
	app.useGlobalFilters(new AllExceptionFilter());

	//全局请求拦截器
	app.useGlobalInterceptors(new RequestInterceptor());

	//全局响应拦截器
	app.useGlobalInterceptors(new ResponseInterceptor());

	//全局日志拦截器
	app.useGlobalInterceptors(new LoggingInterceptor());

	//启动服务
	await app.listen({
		port: config().port,
		host: '0.0.0.0',
	});
}
bootstrap();
